<template>
  <BaseMainSlot>
    <template v-slot:searchbox>
      <el-collapse v-model="activeName" accordion @change="handleChange">
        <el-collapse-item name="1">
          <template slot="title">
            <div class="select-btns search-btns" @click.stop="changeSelect()">
              <i class="el-icon-circle-check"></i>
              <p v-if="activeName === '1'">收起筛选</p>
              <p v-if="activeName === ''">展开筛选</p>
            </div>
          </template>
          <div class="search-btn search-btns" @click.stop="queryPageList(), searchPage()">
            <i class="el-icon-circle-check"></i>
            <p>查询</p>
          </div>
          <!-- <div class="select-box-content">
            <div class="select-box-content-name">采购订单编号</div>
            <el-input v-model="purchaseOrderId" clearable />
          </div> -->
          <!-- <div class="select-box-content">
            <div class="select-box-content-name">批次编号</div>
            <el-input v-model="mnecode" clearable />
          </div> -->
          <div class="select-box-content">
            <div class="select-box-content-name">选择鱼塘</div>
            <el-select filterable clearable v-model="fishPondId" filterable clearable @change="() => {
              mnecode = ''
            }">
              <el-option v-for="(item, index) in fishPondList" :key="index" :label="item.pondName"
                :value="item.fishPondId" />
            </el-select>
          </div>
          <div class="select-box-content">
            <div class="select-box-content-name">批次编号</div>
            <el-select filterable clearable v-model="mnecode" filterable clearable>
              <template v-for="(item, index) in batchList">
                <el-option v-if="fishPondId == item.fishPondId || !fishPondId" :key="index"
                  :label="`${item.mnecode}_${item.varietyName}`" :value="item.mnecode" />
              </template>
            </el-select>
          </div>
          <div class="select-box-content">
            <div class="select-box-content-name">投塘品种</div>
            <el-select filterable clearable v-model="fishVarietyId" filterable clearable>
              <el-option v-for="(item, index) in FishVarietyData" :key="index" :label="item.varietyName"
                :value="item.fishVarietyId" />
            </el-select>
          </div>
          <div class="select-box-content">
            <div class="select-box-content-name">投塘人</div>
            <el-select filterable clearable v-model="staffName" filterable clearable>
              <el-option v-for="(item, index) in staffList" :key="index" :label="item.staffName"
                :value="item.staffName" />
            </el-select>
          </div>
          <div class="select-box-content">
            <div class="select-box-content-name">投塘日期</div>
            <el-date-picker v-model="inputDate" type="date" placeholder="选择日期" value-format="yyyy-MM-dd" clearable />
          </div>
        </el-collapse-item>
      </el-collapse>
    </template>
    <template v-slot:btnsBar>
      <ActionBar :export-active="true" :hasExport="true" :hasAdd="false" :hasDel="false" :page-no="162" @add="add"
        @del="del" @exportFile="exportFile" />
    </template>
    <template v-slot:content>
      <el-table ref="tableData" v-loading="loading" highlight-current-row :data="tableData" class="margin-top10px" stripe
        border height="calc(100% - 50px)" :row-key="row => {
          return row.inputPondDetailId;
        }
          ">
        <!-- <el-table-column type="selection" width="55" :reserve-selection="true" :selectable="(row) => { return !row.selectable }" /> -->
        <el-table-column type="index" label="序号" width="50">
          <template slot-scope="scoped">
            {{ scoped.row.inputPondDetailId ? scoped.$index + 1 : '' }}
          </template>
        </el-table-column>
        <!-- <el-table-column prop="mnecode" label="关联采购订单" /> -->
        <el-table-column prop="mnecode" label="批次编号" />
        <el-table-column prop="productionBatchCode" label="码单号" />
        <el-table-column prop="fishVarietyName" label="品种名称" />
        <el-table-column prop="specificationName" label="投入规格" />
        <el-table-column prop="inputNum" label="投入数量（尾）" />
        <el-table-column prop="inputWeight" label="投入重量（斤）" />
        <el-table-column prop="pondName" label="投入鱼塘名称" />
        <el-table-column prop="pondArea" label="鱼塘面积">
          <template v-if="scoped.row.inputPondDetailId" slot-scope="scoped">
            {{ scoped.row.pondArea + scoped.row.areaUnitStr }}
          </template>
        </el-table-column>
        <el-table-column prop="staffName" label="投塘人" />
        <el-table-column prop="inputDate" label="投塘日期" />
      </el-table>
      <ExportBtn ref="ExportBtn" :btnName="'投塘报表'" :apiName="'inputPondExport'" :searchObj="searchObj"></ExportBtn>
      <Pagination :page-size="pageSize" :current-page="currentPage" :total-size="totalSize"
        @changeCurrentPage="changeCurrentPage" />
    </template>
  </BaseMainSlot>
</template>

<script>
import ActionBar from "@/components/ActionBar";
import Pagination from "@/components/Pagination";
import BaseMainSlot from "@/components/BaseMainSlot/kong-new2.vue";
import ExportBtn from "@/components/ExportBtn";
import { mymixin } from "@/utils/mixin";
import { mapGetters } from 'vuex';

import BatchMangeApi from "@/api/batch-mange"
import InputPondApi from "@/api/inputPond"
import FishVarietyApi from "@/api/basic-info-manage/fishVariety"
import FishPondApi from "@/api/basic-info-manage/fishPond"
import StaffApi from "@/api/basic-info-manage/staff";
export default {
  name: 'HistoryInputPondRecord',
  components: { ActionBar, Pagination, BaseMainSlot, ExportBtn },
  mixins: [mymixin],
  data () {
    return {
      searchObj: {},
      mnecode: "",//批次编号
      purchaseOrderId: "",//采购订单编号
      fishPondId: "",//养殖鱼塘ID
      fishVarietyId: "",//养殖品种ID
      staffName: '',//投塘人
      inputDate: "",//投塘日期
      checkedIdList: [],
      fishPondList: [],//全部鱼塘
      FishVarietyData: [],//全部品种
      staffList: [],//全部员工/投塘人
      batchList: [],
      //分类列表
      categoryList: [
        {
          categoryName: '鱼苗投入',
          status: "UN_COMPLETE"
        },
        {
          categoryName: '成鱼投入',
          status: "COMPLETED"
        },
      ],
      showAddEditDialog: false,
      activeName: '',//控制是否默认展开
    };
  },
  computed: {
    ...mapGetters({
      judgePermission: "permission/judgePermission"
    })
  },
  watch: {},
  created () {
    this.queryPageList();
  },
  mounted () {
    this.queryFishVariety()
    this.queryFishPond()
    this.queryBatchMange()
    this.queryStaff()
  },
  methods: {
    // 查询可选批次
    queryBatchMange () {
      BatchMangeApi.queryByCondition({}).then(res => {
        this.batchList = res.data;
      })
    },
    searchPage () {
      this.currentPage = 1
      this.queryPageList();
      setTimeout(() => {
        this.queryPageList();
      }, 200);
    },
    queryPageList () {
      let params = {
        page: this.currentPage,
        size: this.pageSize,
        sortStr: "ip.createTime",
        order: "desc",
        entity: {}
      };
      if (this.mnecode) params.entity.mnecode = this.mnecode;
      if (this.productionBatchCode) params.entity.productionBatchCode = this.productionBatchCode;
      if (this.fishPondId) params.entity.fishPondId = this.fishPondId;
      if (this.fishVarietyId) params.entity.fishVarietyId = this.fishVarietyId;
      if (this.staffName) params.entity.staffName = this.staffName;
      if (this.status) params.entity.status = this.status;
      if (this.inputDate) params.entity.inputDate = this.inputDate;

      this.searchObj = JSON.parse(JSON.stringify(params.entity))
      InputPondApi.queryPageByCondition(params).then(res => {
        if (res.success === true) {
          let data = res.data || {};
          this.totalSize = data.totalElements;
          // 赋值数组
          this.tableData = data.content;
          this.addblankmet();
          this.resetActionBar();
        }
      });
    },
    //查询可选鱼类品种
    queryFishVariety () {
      let params = {
        page: 1,
        size: 10000,
      }
      FishVarietyApi.queryPageByCondition(params).then(res => {
        this.FishVarietyData = res.data.content;
      })
    },
    //查询可选鱼塘
    queryFishPond () {
      let params = {
        page: 1,
        size: 10000,
      }
      FishPondApi.queryPageByCondition(params).then(res => {
        this.fishPondList = res.data.content;
      })
    },
    //查询投塘人
    queryStaff () {
      let params = {
        page: 1,
        size: 100000,
      }
      StaffApi.queryPageByCondition(params).then(res => {
        this.staffList = res.data.content;
      })
    },
    //批次分类切换
    categoryChange (item) {
      this.status = item.status
      this.queryPageList()
    },
    changeCurrentPage (currentPage) {
      this.currentPage = currentPage;
      this.queryPageList();
    },
    selectAll (list) {
      let notvalue = true
      list.forEach(item => {
        if (!item.inputPondDetailId) {
          notvalue = false
        }
      });
      if (notvalue === false) {
        this.$message.warning("不可选择空数据！");
      }
    },
    select (list) {
      let notvalue = true
      list.forEach(item => {
        if (!item.inputPondDetailId) {
          notvalue = false
        }
      });
      if (notvalue === false) {
        this.$message.warning("不可选择空数据！");
      }
    },
    handleSelectionChange (list) {
      this.checkedIdList = [];
      let notvalue = true
      let emptyList = []
      this.checkedIdList = list.map(item => {
        if (item.inputPondDetailId) {
          return item.inputPondDetailId
        } else {
          notvalue = false
          emptyList.push(item)
          return ""
        }
      });
      if (notvalue === false) {
        // this.$message.warning("不可选择空数据！");
        this.toggleNoSelection(emptyList)
        return
      }
      if (this.checkedIdList.length >= 1) this.delActive = true;
      else this.delActive = false;
    },
    // 单个删除
    delOne (row) {
      this.$confirm("此操作将永久删除该项, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        
      })
        .then(() => {
          BatchMangeApi.delById({ id: row.inputPondDetailId }).then(res => {
            if (res.success === true) {
              this.$message.success("删除成功!");
              this.queryPageList();
              this.resetActionBar();
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除"
          });
        });
    },
    // 添加
    add () {
      this.nowChanceStau = 'add'
      this.titleText = "添加"
      this.addActive = false;
      this.delActive = false;
      this.showAddEditDialog = true
    },
    // 修改
    edit (row) {
      if (row.inputPondDetailId) {
        this.editObject = JSON.parse(JSON.stringify(row));
        this.nowChanceStau = 'edit'
        this.titleText = "修改"
        this.addActive = false;
        this.delActive = false;
        this.showAddEditDialog = true
      } else {
        this.editObject = {}
      }
    }
  }
};
</script>

<style lang="scss" scoped></style>
